<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once 'Mysql.php';
//TO DO create function verfy data ;
session_start();
/* if the session variables (login + pass + Question count) not exist 
 * we ask the user for the login and pass
 * then we initialise it
 * */
if(isset($_POST['login']) || isset($_POST['pass'])){
	/* 
	 * we connect to the database to verify login + pass
	 * if the login is correct we set the session variables
	 */  
	 $login = $_POST['login'];
	 $pass = $_POST['pass'];
	 $mysql = new Mysql();
	 $uid = $mysql->verify_login($login,$pass);	 
	 if($uid){
	 	/* login is correct we can naw start the QCM by initalizing the session variabl withe the team id */
	 	$_SESSION['user_id']= $uid;
	 }
	/* 
	 * if the login is incorrect we show again the login_form 
	 * and unset the session variabls  
	 * */
	 else{
	 	echo "login failure";
	 }
}
if(!isset($_SESSION['user_id'])){
	//$_SESSION['QuestionCount']=0; old code
	//$_SESSION['score']= 0;
?>
<html>
<head>
<title>QCM</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<link rel="stylesheet" href="css/style.css"  type="text/css"/>
</head>
<body>
<?php include 'header.php';?>
<div id="content">
<form  name="login_form" method="post">
	<table border="0" align="center">
		<tr><td>Login</td><td><input type="text" name="login" /></td></tr>
		<tr><td>Password</td><td><input type="password" name="pass" /></td></tr>
		<tr><td colspan="2" align="center"><input type="submit" value="Ok" /></td></tr>
	</table>
</form>
</div>
<?php include 'footer.php';?>
</body>
</html>
<?php
}

else{
/* if all the session variabls are set
 * and we can set this varibles until the login and pass is correct
 * */
?>
<html>
<head>
<title>QCM</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<link rel="stylesheet"  href="css/style.css"  type="text/css"/>
</head>
<body onload="start()">
	<?php include 'header.php';?>
	<div id="content">
	<div id="wait"></div>
	<div id="team_name"></div>
	<table border="0" align="center" id="test_table">
		<tr><td colspan="2" align="center"><span id="question"></span></td></tr>
		<tr><td colspan="2" align="center"><span id="image_path"></span></td></tr>
		<tr><td><input id="choix1" type="radio" name="choix" ></td><td><span id="pro1"></span></td></tr>
		<tr><td><input id="choix2" type="radio" name="choix" ></td><td><span id="pro2"></span></td></tr>
		<tr><td><input id="choix3" type="radio" name="choix" ></td><td><span id="pro3"></span></td></tr>
		<tr><td><input id="choix4" type="radio" name="choix" ></td><td><span id="pro4"></span></td></tr>
		<tr><td><input id="choix5" type="radio" name="choix" ></td><td><span id="pro5"></span></td></tr>
		<tr><td><input id="choix6" type="radio" name="choix" ></td><td><span id="pro6"></span></td></tr>
		<tr><td><input id="choix7" type="radio" name="choix" ></td><td><span id="pro7"></span></td></tr>
		<tr><td><input id="choix8" type="radio" name="choix" ></td><td><span id="pro8"></span></td></tr>
		<tr><td><input id="choix9" type="radio" name="choix" ></td><td><span id="pro9"></span></td></tr>
		<tr><td><input id="choix10" type="radio" name="choix" ></td><td><span id="pro10"></span></td></tr>
		<tr><td colspan="2" align="center"><input id="next_button" type="button" value="Suivant" onclick="NextQuestion()"></td></tr>
	</table>
	<div id="score" align="center"></div>
	</div>
	<?php include 'footer.php';?>
</body>
</html>
<?php	
}

?>
